<div xmlns:ext="http://www.extjs.com" class="body-wrap"><h1>Class <a href="source/JSONP.html#cls-Ext.util.JSONP">Ext.util.JSONP</a></h1><table cellspacing="0"><tr><td class="label">Package:</td><td class="hd-info">Ext.util</td></tr><tr><td class="label">Defined In:</td><td class="hd-info"><a href="source/JSONP.html#cls-Ext.util.JSONP">JSONP.js</a></td></tr><tr><td class="label">Class:</td><td class="hd-info"><a href="source/JSONP.html#cls-Ext.util.JSONP">JSONP</a></td></tr><tr><td class="label">Extends:</td><td class="hd-info">Object</td></tr></table><div class="description">Provides functionality to make cross-domain requests with JSONP (JSON with Padding).
http://en.wikipedia.org/wiki/JSON#JSONP
<p>
<b>Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain
of the running page, you must use this class, because of the same origin policy.</b><br>
<p>
The content passed back from a server resource requested by a JSONP request<b>must</b> be executable JavaScript
source code because it is used as the source inside a &lt;script> tag.<br>
<p>
In order for the browser to process the returned data, the server must wrap the data object
with a call to a callback function, the name of which is passed as a parameter callbackKey
Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
depending on whether the callback name was passed:
<p>
<pre><code>boolean scriptTag = false;
String cb = request.getParameter(<em>"callback"</em>);
<b>if</b> (cb != null) {
    scriptTag = true;
    response.setContentType(<em>"text/javascript"</em>);
} <b>else</b> {
    response.setContentType(<em>"application/x-json"</em>);
}
Writer out = response.getWriter();
<b>if</b> (scriptTag) {
    out.write(cb + <em>"("</em>);
}
out.print(dataBlock.toJsonString());
<b>if</b> (scriptTag) {
    out.write(<em>");"</em>);
}</code></pre>
<p>Below is a PHP example to do the same thing:</p><pre><code>$callback = $_REQUEST[<em>'callback'</em>];

<i>// Create the output object.</i>
$output = array(<em>'a'</em> => <em>'Apple'</em>, <em>'b'</em> => <em>'Banana'</em>);

<i>//start output</i>
<b>if</b> ($callback) {
    header(<em>'Content-Type: text/javascript'</em>);
    echo $callback . <em>'('</em> . json_encode($output) . <em>');'</em>;
} <b>else</b> {
    header(<em>'Content-Type: application/x-json'</em>);
    echo json_encode($output);
}</code></pre>
<p>Below is the ASP.Net code to do the same thing:</p><pre><code>String jsonString = <em>"{success: true}"</em>;
String cb = Request.Params.Get(<em>"callback"</em>);
String responseString = <em>""</em>;
<b>if</b> (!String.IsNullOrEmpty(cb)) {
    responseString = cb + <em>"("</em> + jsonString + <em>")"</em>;
} <b>else</b> {
    responseString = jsonString;
}
Response.Write(responseString);</code></pre><br><br><i>This class is a singleton and cannot be created directly.</i></div><div class="hr"></div><a id="Ext.util.JSONP-props"></a><h2>Public Properties</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Property</th><th class="msource-header">Defined By</th></tr><tr class="property-row  "><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.util.JSONP-current"></a><b><a href="source/JSONP.html#prop-Ext.util.JSONP-current">current</a></b> : Object<div class="mdesc">Read-only current executing request</div></td><td class="msource">JSONP</td></tr><tr class="property-row  "><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.util.JSONP-queue"></a><b><a href="source/JSONP.html#prop-Ext.util.JSONP-queue">queue</a></b> : Array<div class="mdesc">Read-only queue</div></td><td class="msource">JSONP</td></tr></tbody></table><a id="Ext.util.JSONP-methods"></a><h2>Public Methods</h2><table cellspacing="0" class="member-table"><tbody><tr><th colspan="2" class="sig-header">Method</th><th class="msource-header">Defined By</th></tr><tr class="method-row expandable "><td class="micon"><a href="#expand" class="exi">&nbsp;</a></td><td class="sig"><a id="Ext.util.JSONP-request"></a><b class="method"><a href="source/JSONP.html#method-Ext.util.JSONP-request">request</a></b><span class="openparen">(&nbsp;</span><span title="Required" class="required">Object&nbsp;config</span><span class="closeparen">&nbsp;)</span><span class="colon">&nbsp;:&nbsp;</span><span class="return">void</span><div class="mdesc"><div class="short">Make a cross-domain request using JSONP.</div><div class="long">Make a cross-domain request using JSONP.<div class="mdetail-params"><strong>Parameters:</strong><ul><li><code>config</code> : Object<div class="sub-desc">Valid configurations are:
<ul>
<li>url - {String} - Url to request data from. (required) </li>
<li>params - {Object} - A set of key/value pairs to be url encoded and passed as GET parameters in the request.</li>
<li>callbackKey - {String} - Key specified by the server-side provider.</li>
<li>callback - {Function} - Will be passed a single argument of the result of the request.</li>
<li>scope - {Scope} - Scope to execute your callback in.</li>
</ul></div></li></ul><strong>Returns:</strong><ul><li>void</li></ul></div></div></div></td><td class="msource">JSONP</td></tr></tbody></table><a id="Ext.util.JSONP-events"></a><h2>Public Events</h2><div class="no-members">This class has no public events.</div></div>